package com.buobao.mybatis.annotationtest.dao;

import com.buobao.mybatis.annotationtest.dto.GoodDTO;
import com.buobao.mybatis.annotationtest.entity.Goods;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface GoodsDAO {
    @Select("select * from t_goods where current_price between #{min} and #{max} limit #{limit}")
    List<Goods> selectByPriceRange(@Param("min") Float min,@Param("max") Float max,@Param("limit") Integer limit);

    @Insert("insert into t_goods(title,sub_title,original_cost,current_price,discount,is_free_delivery,category_id) values(#{title},#{subTitle},#{originalCost},#{currentPrice},#{discount},#{isFreeDelivery},#{categoryId})")
    @SelectKey(statement = "select last_insert_id()",before = false,resultType = Integer.class ,keyProperty = "goodsId")
    int insert(Goods goods);

//    @Select("select * from t_goods")
//    @ResultMap(value = {
//            @Result(column = "goods_id", property = "goodsId", id = true),
//            @Result(column = "title", property = "title"),
//            @Result(column = "current_price",property = "currentPrice")
//    })
    List<GoodDTO> selectALlGoods();
}
